#!/usr/bin/perl -w
use strict;
use Getopt::Long;
use lib "/net/cpp-group/Leo/bin";
use parse_fasta;
#88888888888888888888888888888888888888888888888888888888888888888888888888888888

#   Usage

#88888888888888888888888888888888888888888888888888888888888888888888888888888888
my $usage = <<"USAGE";

USAGE:

    kaks_results_to_ks_matrix.pl [--threshold 5.0] < kaks.results > ks.matrix [--help]
		
		This script accepts results from seq_pairs_kaks on
		STDIN produces a ks matrix with values above THRESHOLD
		(ks == 5.0) set to null

USAGE

#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

#   Get options

#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
# mandatory


# optional parameters
my $help = undef;
my $threshold = 5;
GetOptions(
	'threshold' => \$threshold,
	'help' => \$help);

die $usage if ($help);

open (EXE, "| /net/cpp-group/Leo/bin/matrix_extract_data -i p -o s -v")
							or die "Error\n\tCould not open matrix_extract_data\n";

my $line_count = 0;
while (<STDIN>)
{
	$line_count++;
	my ($name1, $name2, undef, $ks) = split /\t/;
	print EXE join ("\t", $name1, $name2, $ks, "\n") if $ks < $threshold;
}
